from time import sleep

from selenium.webdriver.common.by import By

from base.base import Base


class MPAPage(Base):


    goods_manager = (By.XPATH, '//span[text()="商场管理"]')

    def gm_f(self):
        self.loc_wait_ele(self.goods_manager).click()


    bp=(By.XPATH,'//span[text()="品牌制造商"]')
    def bp_f(self):
        self.loc_wait_ele(self.bp).click()

    ab=(By.XPATH,'//span[text()="添加"]')
    def ab_f(self):
        self.loc_wait_ele(self.ab).click()

    bn=(By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div.el-form-item.el-form-item--feedback.is-required.el-form-item--mini > div > div > input")
    def bu_f(self,n):
        self.loc_wait_ele(self.bn).send_keys(n)

    dp=(By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(2) > div > div > input")
    def dp_f(self,i):
        self.loc_wait_ele(self.dp).send_keys(i)

    iu=(By.NAME,"file")
    def iu_f(self,f):
        self.loc_wait_ele(self.iu).send_keys(f)
        # self.loc_wait_ele(self.iu).click()
        # sleep(2)
        # self.switch_window(-1)


    p=(By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(4) > div > div > input")
    def p_f(self,t):
        self.loc_wait_ele(self.p).send_keys(t)

    #cb=(By.XPATH,'//span[text()="确定"]')
    cb=(By.XPATH,'//div[@class="dialog-footer"]/button[2]')
    def cb_f(self):
        self.loc_wait_ele(self.cb).click()


    # fi=(By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.filter-container > div:nth-child(2) > input")
    # def fi_f(self,n):
    #     self.loc_wait_ele(self.fi).send_keys(n)
    #
    #
    # f=(By.XPATH,'//span[text()="查找"]')
    # def f_f(self):
    #     self.loc_wait_ele(self.f).click()

    jd=(By.XPATH,'//span[text()="创建"]')
    def jd_f(self):
        return self.loc_wait_ele(self.jd).text


    dialog=(By.CSS_SELECTOR,"body > div.el-notification.right > div > div.el-notification__content > p")
    def dialog_f(self):

        return self.loc_wait_ele(self.dialog)


    def mpa_bus(self,n,i,f,t):
        self.gm_f()
        self.bp_f()
        self.ab_f()
        sleep(2)
        self.bu_f(n)
        self.dp_f(i)
        # if f != '':
        #     self.iu_f(f)
        #     sleep(2)
        #self.iu_f()
        sleep(2)
        self.p_f(t)
        self.cb_f()
        sleep(2)

        r=self.dialog_f()


        print("弹窗：",r)
        if r is None:
            return self.jd_f() or "未找到预期元素"
        else:
            return r.text or "操作完成"  # 防止返回None





